/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.deib.se2.meteocal.business.boundary;

import it.polimi.deib.se2.meteocal.business.entity.Calendar;
import java.security.Principal;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class CalendarManager {
    
    @PersistenceContext
    EntityManager em;
    UserManager um;
    @Inject
    Principal principal;
    
    public void save(Calendar cal) {
        em.persist(cal);
    }
    
    public void remove(Calendar calendar){
        em.remove(calendar); //se non va fare em.remove(em.merge(calendar));
    }
    
    public Calendar getActiveCalendar() {
        return em.find(Calendar.class, um.getLoggedUser().getCalendar().getId());
    }
    
    public void editCalendar(Calendar calendar) {
        em.merge(calendar);
    }
}
